﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SqliteLoader
{
	public partial class TablesDialog : Form
	{
		public TablesDialog()
		{
			InitializeComponent();
		}

		public Mapping Dataset { get; set; }

		private void TablesDialog_Load(object sender, EventArgs e)
		{
			tableMappingGrid.AutoGenerateColumns = false;
			tableMappingGrid.DataSource = Dataset.TableMapping;
			colSource.DataPropertyName = Dataset.TableMapping.SourceColumn.ColumnName;
			colDestination.DataPropertyName = Dataset.TableMapping.DestinationColumn.ColumnName;
			
			colDestination.DataSource = Dataset.TableDef;
			colDestination.DisplayMember = Dataset.TableDef.NameColumn.ColumnName;
		}

		private void cancelButton_Click(object sender, EventArgs e)
		{

		}

		private void editMappingButton_Click(object sender, EventArgs e)
		{
			if(tableMappingGrid.SelectedRows.Count == 0) return;

			var row = tableMappingGrid.SelectedRows[0];
			var mapping = row.DataBoundItem as Mapping.TableMappingRow;
			if (mapping == null) return;

			using (var columnMapping = new TableDialog())
			{
				columnMapping.Mapping = mapping;
				columnMapping.ShowDialog(this);
			}
		}
	}
}
